<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	
	<style type="text/css">
	    .errorText
	    {
	        color:red;
	    }
    </style>
</head>
<body>
	<form id="form1" method="post">
        <div style="padding-left:30px;padding-bottom:5px;padding-top: 25px;">
            <table cellspacing="5" cellpadding="0">
            	<tr>
            		<td style="width: 100px;">号码类型：</td>
            		<td>
            			<div name="numType" class="mini-radiobuttonlist" repeatLayout="table" repeatDirection="horizontal" textField="keyValue" valueField="keyName" value="30" url="dictionary_cm_key_val_view.do?typeName=CUSTOMER_PHONE_TYPE" >
            			</div>
            		</td>
            	</tr>
            	<tr>
            		<td colspan="2">
            			<input emptyText="请输入相关号码" labelField="true" label="相关号码：" labelStyle="width: 100px;" errorMode="none" onvalidation="checkValidation" requiredErrorText="号码不能为空" vtype="int;rangeChar:7,12;numType;numOnly" name="relatedPhone" style="width: 300px;" class="mini-textbox" required="true" />
            		</td>
            		<td id="relatedPhone_error" class="errorText" ></td>
            	</tr>
            	<tr>
            		<td colspan="2">    
                        <input emptyText="请选择..." showNullItem="true" nullItemText="全部" labelField="true" label="任务类别：" labelStyle="width: 100px;" errorMode="none" onvalidation="checkValidation" requiredErrorText="请选择任务类别" id="category" name="category" style="width: 300px;" onvalidation="checkValidation" class="mini-combobox" required="true" valueField="keyName" style="width: 220px" textField="keyValue" url="" />
                    </td>
                    <td id="category_error" class="errorText" ></td>
            	</tr>
            	<tr>
            		<td colspan="2">
                		<textarea labelField="true" label="备注：" errorMode="none" onvalidation="checkValidation" labelStyle="width: 100px;" style="width: 300px;height: 70px;" name="remark" class="mini-textarea" emptyText="请输入备注" vtype="maxLength:85"></textarea>   
                	</td>
                	<td id="remark_error" class="errorText" ></td>
            	</tr>
            </table>
        </div>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:50px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>
</body>
</html>

<script type="text/javascript">
	mini.parse();
	
	// 加载话务类别数据
	var category = mini.get('category');
	category.load('dictionary_cm_key_val_view.do?typeName=CALL_TASK_TYPE');
	
	var form = new mini.Form("form1");
	
	// 保存数据
    function onOk(e) {
    	var o = form.getData(true); 
	    form.validate();
	    if (form.isValid() == false) return;
	    $.ajax({
	        url: "call_allocate_save.do",
			type: 'post',
			dataType: 'json',
	        data: o,
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误！");
	            }
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert(jqXHR.responseText);
	            window.CloseOwnerWindow();
	        }
	    });
    }
    
    function onCancel(e) {
    	window.CloseOwnerWindow("cancel");
    }
    
    // 验证号码格式
   	mini.VTypes["numTypeErrorText"] = "号码格式不正确";
    mini.VTypes["numType"] = function (v) {
    	var reMobile = new RegExp("^0?1[34578]\\d{9}$");
    	var rePhone = new RegExp("^(010|02\\d|0[3-9]\\d{2})?\\d{7,8}$");
    	if(reMobile.test(v)) {
    		return true;
    	} else if(rePhone.test(v)) {
    		return true;
    	} else {
    		return false;
    	}
    }
    
    // 验证号码唯一
    mini.VTypes["numOnlyErrorText"] = "此号码任务已存在，请重新输入！";
    mini.VTypes["numOnly"] = function (v) {
    	var flag = true;
    	$.ajax({
  	    	url: "call_valid_phone.do?relatedPhone=" + v,
  	    	dataType: 'json',
  	        cache: false,
	    	async: false,
 	        success: function (text) {
 	            if(text.success){
 	            	flag = true;
 	            }else{
 	            	flag = false;
 	            }
 	        }
  	    });
    	return flag;
    }
    
    function updateError(e) {
        var id =e.sender.name + "_error";
        var el = document.getElementById(id);
        if (el) {
            el.innerHTML = e.errorText;
        }
    }
    
    function checkValidation(e) { 
        updateError(e);
    }
</script>